package thread;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/27
 * Time:20:12
 * 张三李四举例
 **/
public class ThreadDemo15 {
    public static void main(String[] args) throws InterruptedException {
        //定义公共任务
        Runnable runnable = new Runnable(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "上班");
                try {
                    Thread.sleep(1000);//表示工作时间
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "下班");
            }
        };
        //定义张三
        Thread t1 = new Thread(runnable,"张三");
        t1.start();

        //等到张三执行完成
        t1.join();

        //定义李四
        Thread t2 = new Thread(runnable,"李四");
        t2.start();
    }
}
